<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/order-sub1.css" />
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="refreshContainer" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view" id="OA_task_1">
					<!--	<li class="mui-table-view-cell  mui-media">
						<div class="mui-slider-right mui-disabled">
							<a class="mui-btn mui-btn-red">删除</a>
						</div>
						<div class="mui-slider-handle">
							<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
							<div class="mui-media-body ">
								礼盒装人参 <span <span class="mui-pull-right statue1">等待结清货款</span>
								<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
							</div>
							<div class="btn">
								<span>委托交易</span>
								<span>结清货款</span>
								<span class="mui-pull-right">延期</span>
							</div>
						</div>

					</li>

				</ul>
				<p class="statue">状态1</p>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
						<div class="mui-media-body">
							礼盒装人参 <span <span class="mui-pull-right">已结清</span>
							<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
						</div>
					</li>
					<li class="mui-table-view-cell mui-media">
						<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
						<div class="mui-media-body">
							礼盒装人参 <span <span class="mui-pull-right">已结清</span>
							<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
						</div>
					</li>

				</ul>
				<p class="statue">状态2</p>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
						<div class="mui-media-body">
							礼盒装人参 <span <span class="mui-pull-right statue1">已违约</span>
							<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
						</div>
						<div class="btn">
							<span>委托交易</span>
							<span>结清货款</span>
							<span class="mui-pull-right">延期</span>
						</div>
					</li>

				</ul>
				<p class="statue">状态3</p>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
						<div class="mui-media-body">
							礼盒装人参 <span <span class="mui-pull-right">交易失败</span>
							<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
						</div>
					</li>

				</ul>
				<p class="statue">状态4</p>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<img class="mui-media-object mui-pull-left" src="../images/shangpin.png">
						<div class="mui-media-body">
							礼盒装人参 <span <span class="mui-pull-right statue2">待批货</span>
							<p>实购数量：2 <span class="mui-pull-right">￥ 1000.00</span></p>
						</div>
					</li>

				</ul>
				<p class="statue">状态5</p>-->
			</div>
		</div>
		<script src="../lib/mui.min.js"></script>
		<script type="text/javascript" src="../lib/jquery-1.11.0.js"></script>
		<script type="text/javascript" src="../lib/service.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.init({
				pullRefresh: {
					container: '#refreshContainer',
					down: {
						callback: pullDownfresh
					},
					up: {
						callback: pullUpfresh
					}
				}
			});
			pullDownfresh()

			function pullDownfresh() {
				getServer('app/member/myOrders', $.param({
					orderType: 0
				}), function(res) {
					console.log(JSON.stringify(res))
					//				console.log(res.data.code)
					$('.mui-table-view').html(editlist(res.data.orders))
					mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
				});
				//                setTimeout(
				//                       function() {
				//                          alert( "下拉刷新" );
				//                          mui( '#refreshContainer').pullRefresh().endPulldownToRefresh();
				//                       }, 1000);
			}

			function pullUpfresh() {
				var self = this;
				//				setTimeout(
				//					function() {
				//						alert("上拉加载");
				self.endPullupToRefresh(false);
				//					}, 1000);
			}

			function editlist(data) {
				var str = ""
				for(var i = 0; i < data.length; i++) {
					str += '<li class="mui-table-view-cell mui-media" >'
					str += '<div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red" id="' + data[i].id + '">删除</a></div>'
					str += '<div class="mui-slider-handle" id="' + data[i].id + '">'
					str += '<img class="mui-media-object mui-pull-left" src="' + serverUrl + 'upload/' + data[i].productImg + '">'
					str += '<div class="mui-media-body">'+data[i].productName
					str += ' <span <span class="mui-pull-right">' + data[i].statusStr + '</span>'
					str += '<p>实购数量：' + data[i].productNum + ' <span class="mui-pull-right">￥ ' + data[i].productMoney + '</span></p>'
					str += '</div></div><div class="btn">'
					str += '			<span class="weituo">委托交易</span>'
					str += '			<span class="settlement">结清货款</span>'
					str += '		</div></li>'
				}
				return str;
			}
			$('.mui-table-view').on('tap', '.mui-slider-handle', function() {
				console.log($(this).attr('id'))

				openurl('../buy/order_details.html', JSON.stringify({
					id: $(this).attr('id'),
					type: 1
				}))
			})
			$('.mui-table-view').on('tap','div.btn .weituo ',function(){
				getServer('app/member/gxLogin', "", function(res) {
					plus.nativeUI.closeWaiting()
					console.log(JSON.stringify(res))
					var url = {
						url :res.data.authUrl
					}
					openurl('../home/gongxiaoDetatal.html', JSON.stringify(url))
				});
			})
			$('.mui-table-view').on('tap','div.btn .settlement ',function(){
				openurl('../auth/servicelist.html')
			})
			$('.mui-table-view').on('tap', '.mui-btn', function(event) {

				var elem = this;
				var li = elem.parentNode.parentNode;
				var id = $(this).attr('id')
				mui.confirm('确认删除该条记录？', '火速购', btnArray, function(e) {
					if(e.index == 0) {
//						if(delData(id)){
							delData(id)
							li.parentNode.removeChild(li);
//						}
						
					} else {
						setTimeout(function() {
							$.swipeoutClose(li);
						}, 0);
					}
				});
			});
			var btnArray = ['确认', '取消'];

			function delData(id) {
				var  flag = false;
				console.log(id)
				var subData={
					id:id
				}
				postServer('/app/member/postDelete', $.param(subData), function(res) {
					 console.log(JSON.stringify(res))
					 flag = true
					 return flag
				}, function(res) {
					 mui.toast(res.message)
				});
//				alert(flag)
				
			}
		</script>
	</body>

</html>